{include $data.pathToError}
<script type="text/javascript">
    {literal}
        
    function sendAction(action){
        $("#action").val(action);
        $("#adding").submit();    
    }
        
    function showOther(){
        var display = $("#otherTable").css("display");
        if (display == "none"){
            $("#other").empty();
            $("#other").append("- Task features");
            $("#otherTable").show();
            $("#showOther").val("1");
        } else {
            $("#other").empty();
            $("#other").append("+ Task features");
            $("#otherTable").hide();
            $("#showOther").val("0");
        }
    }
    
    function showTaskTypeTable(id){
        $("#taskType").removeClass("bgSpecial1");
        $(".external").hide();    
        if (id==8 || id==9){
            $("#taskType").addClass("bgSpecial1");
            $("#taskType"+id).show();
        }
    }
    
    function change_responsible(id){
        if (id!=""){
            $("#responsible option[value="+id+"]").attr("selected", "selected");
            $("#worker option[value="+id+"]").attr("selected", "selected");
        }
    }
        
    function change_worker(id){
        $("#worker option").removeAttr("selected");
        $("#worker option[value="+id+"]").attr("selected", "selected");
    }
        
    $(document).ready(function() {
        $("#task_start").datepicker({ 
            dateFormat: "dd/mm/yy",
            firstDay: 1      
        });
        $("#deadline").datepicker({ 
            dateFormat: "dd/mm/yy",
            firstDay: 1    
        });
        $("#date_of_action").datepicker({ 
            dateFormat: "dd/mm/yy" ,
            firstDay: 1     
        }); 
        $("#delivery").datepicker({ 
            dateFormat: "dd/mm/yy",
            firstDay: 1      
        });    
        $(".float").change(function() {
            makeFloat(".float",1);
        });
        change_responsible($('#client option:selected').attr("rel"));
        $("#title").focus();
    });
    {/literal}
</script>

<h2 class="pageTitle">Add task</h2>

<form class="adding" id="adding" action="{$data.root}?input=add_task" method="post" onsubmit="return checkAdd_task(
                                                                    $('#title').val(), 
                                                                    $('#client').val(),
                                                                    $('#responsible').val(),
                                                                    $('#deadline').val(), 
                                                                    $('#type').val(), 
                                                                    $('input:radio[name=task[status]]:checked').val(), 
                                                                    $('input:radio[name=task[priority]]:checked').val(), 
                                                                    'prazdno',
                                                                    $('#duration').val())">
    <table class="tableForm">
        <tr>
            <td>
                <label for="title">Title <span class="red">*</span> </label>
            </td>
            <td colspan="2">
                <input name="task[title]" id="title" type="text" size="100" />
            </td>
        </tr>
        <tr>
            <td>
                <label for="client">Client <span class="red">*</span> </label>
            </td>
            <td>
                <select name="task[client]" id="client" size="1" onchange="change_responsible($('#client option:selected').attr('rel'))">
                    <option value="-1">Please select</option>
                    {foreach $data.clients as $key => $client}
                        <option {if $smarty.session.user.user_type_id!=$smarty.const.USER_TYPE_CLIENT && $client.bad_payer==1}class="badPayer"{/if} rel="{$client.contactPerson}" {if isset($smarty.session.user.clientFilter) && $smarty.session.user.clientFilter==$client.klient_id}selected="selected"{elseif $client.klient_id==$smarty.session.user.profile.client}selected="selected"{/if} value="{$client.klient_id}">{$client.name}</option>
                    {/foreach}
                </select>
            </td>
            <td rowspan="5" class="top" style="width: auto; padding: 0; margin: 0;">
                <table class="">
                    <tr>
                        <td>
                            <label for="description">Description <span class="red"></span></label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <textarea cols="70" rows="6" name="task[description]" id="description"></textarea>
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td>
                <label for="responsible">Responsible <span class="red">*</span> </label>
            </td>
            <td>
                <select name="task[responsible]" id="responsible" size="1" onchange="change_worker(this.value)">
                    <option value="-1">Please select</option>
                    {foreach $data.responsibles as $key => $responsible}
                        <option value="{$responsible.users_id}">{$responsible.surname}, {$responsible.name}</option>
                    {/foreach}
                </select>
            </td>
        </tr>
        <tr>
            <td>
                <label for="worker">Worker</label>
            </td>
            <td>
                <select name="task[worker]" id="worker" size="1">
                    <option value="-1">Please select</option>
                    {foreach $data.responsibles as $key => $responsible}
                        <option value="{$responsible.users_id}">{$responsible.surname}, {$responsible.name}</option>
                    {/foreach}
                </select>
            </td>
        </tr>       
        <tr>
            <td>
                <label for="deadline">Deadline <span class="red">*</span> </label>
            </td>
            <td>
                <input name="task[deadline]" id="deadline" type="text" value="00/00/0000" style="width: 70px" />
            </td>
        </tr>
        <tr>
            <td><label for="duration">Expected amount <span class="red">*</span> </label></td>
            <td>
                <input class="float" name="task[duration]" id="duration" style="width: 30px" type="text" size="5" maxlength="5" />
            </td>
        </tr>
        <tr>
            <td>
                <label for="priority">Priority <span class="red">*</span> </label>
            </td>
            <td><b style="font-size: 16px">&DoubleUpArrow;</b>
                {foreach $data.priorities as $key => $priority}
                    <input {if $priority.id==3}checked="checked"{/if}name="task[priority]" type="radio" value="{$priority.id}" />
                {/foreach}<b style="font-size: 16px">&DoubleDownArrow;</b>
            </td>
        </tr>
        <tr>
            <td colspan="3"><a style="color: black; text-decoration: none;" href="javascript: showOther()"><b id="other">+ Task features</b></a></td>
        </tr>
        <tr id="otherTable" class="bgGray">
            <td colspan="3">
                <table style="width: auto">
                    <tr>
                        <td>
                            <label for="status">Status <span class="red">*</span> </label>
                        </td>
                        <td>
                            {foreach $data.statuses as $key => $status}
                                <input {if $status.id_stav==1}checked="checked"{/if}name="task[status]" type="radio" value="{$status.id_stav}" />&nbsp;{$status.stav}<br/>
                            {/foreach}
                        </td>
                        <td></td>
                    </tr>
                    <tr id="taskType">
                        <td>
                            <label for="type">Task type <span class="red">*</span> </label>
                        </td>
                        <td>
                            <select name="task[type]" id="type" size="1" onchange="showTaskTypeTable(this.value)">
                                {foreach $data.types as $key => $type}
                                    <option {if $type.Id==7}selected="selected"{/if} value="{$type.Id}">{$type.type_of_record}</option>
                                {/foreach}
                            </select>
                        </td>
                        <td rowspan="5" id="external">
                            <table class="external bgSpecial1" id="taskType8">
                                <tr>
                                    <td>Expected date of delivery</td>
                                    <td><input name="goods[delivery]" type="text" id="delivery" /></td>
                                </tr>
                                <tr>
                                    <td>Real delivery time</td>
                                    <td><input name="goods[real]" type="text" /></td>
                                </tr>
                                <tr>
                                    <td>Type of goods</td>
                                    <td>
                                        <select name="goods[type_of_good]" size="1">
                                            {foreach $data.goods_types as $key => $goods}
                                                <option value="{$goods.id}">{$goods.type}</option>
                                            {/foreach}
                                        </select> 
                                    </td>
                                </tr>
                            </table>
                            <table class="external bgSpecial1" id="taskType9">
                                <tr>
                                    <td>Operation</td>
                                    <td>
                                        <select name="operation[operation]" size="1">
                                            <option value="">Please select</option>
                                            {foreach $data.operation_types as $key => $operation}
                                                <option value="{$operation.id}">{$operation.operation}</option>
                                            {/foreach}
                                        </select> 
                                    </td>
                                    <td>Date of operation</td>
                                    <td><input name="operation[date_of_action]" type="text" id="date_of_action" /></td>
                                </tr>
                                <tr>
                                    <td>Name</td>
                                    <td><input name="operation[name]" type="text" /></td>
                                    <td>Surname</td>
                                    <td><input name="operation[surname]" type="text" /></td>
                                </tr>
                                <tr>
                                    <td>Title</td>
                                    <td><input name="operation[title]" type="text" /></td>
                                    <td>External address</td>
                                    <td><input name="operation[address]" type="text" /></td>
                                </tr>
                                <tr>
                                    <td>Phone Number</td>
                                    <td><input name="operation[phone]" type="text" /></td>
                                    <td>Email</td>
                                    <td><input name="operation[email]" type="text" /></td>
                                </tr>
                                <tr>
                                    <td>Position</td>
                                    <td><input name="operation[position]" type="text" /></td>
                                    <td>Department</td>
                                    <td><input name="operation[department]" type="text" /></td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <label for="task_start">Task start <span class="red"></span> </label>
                        </td>
                        <td>
                            <input name="task[task_start]" id="task_start" type="text" value="" />
                            <input name="task[created]" id="created" type="hidden" value="{$data.start}" />
                        </td>
                    </tr>
                    <tr>
                        <td></td>
                        <td></td>
                    </tr>
                    <tr>
                        <td><label for="problem_type">Type of problem</label></td>
                        <td>
                            <select name="task[problem_type]" id="problem_type" size="1" >
                                <option value="">Please select</option>
                                {foreach $data.problem_types as $key => $ptype}
                                    <option value="{$ptype.id}">{$ptype.problem}</option>
                                {/foreach}
                            </select>
                        </td>
                    </tr>
                    <tr>
                        <td><label for="consult">Consult at a meeting</label></td>
                        <td>
                            <input name="task[consult]" id="consult" type="checkbox" value="1" />
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr class="submitRow">
            <td>
                <input name="action" value="addTask" type="hidden" id="action" />
                <span class="red">* Required</span>
            </td>
            <td colspan="2">
                <input type="button" value="Save" name="add_task" onclick="sendAction('addTask')" /> &nbsp; 
                {*<input type="button" value="Write & Complete" name="add_task" onclick="sendAction('addTask_complete')" /> &nbsp; 
                <input type="button" value="Write & TimesheetRecord" name="add_task" onclick="sendAction('addTask_record')" /> &nbsp; 
                <input type="button" value="Write & TimesheetRecord & Complete" name="add_task" onclick="sendAction('addTask_record_complete')" /> &nbsp; 
                <br/>
                *}<input type="button" value="Save & Send" name="add_task" onclick="sendAction('addTask_send')" /> &nbsp; 
                <input type="button" value="Save & Complete & Send" name="add_task" onclick="sendAction('addTask_complete_send')" /> &nbsp; 
                {*<input type="button" value="Write & TimesheetRecord & Send" name="add_task" onclick="sendAction('addTask_record_send')" /> &nbsp; 
                <input type="button" value="Write & TimesheetRecord & Complete & Send" name="add_task" onclick="sendAction('addTask_record_complete_send')" /> &nbsp; *}
            </td>
        </tr>
    </table>
</form>